package 分类.二分;

import java.util.ArrayList;
import java.util.Arrays;

public class 二分查找 {
    public static int search(int[] nums, int target) {
        int left=0;
        Arrays.sort(nums);
        int right=nums.length-1;
        while (left<=right){
            int mid=(left+right)/2;
            if(nums[mid]<target) right=mid-1;
            if(nums[mid]>target) left=mid+1;
            else return mid;
        }
        return -1;
    }

    public static void main(String[] args) {
        int[] arr={-1,0,3,5,9,12};
        System.out.println(search(arr,3));
    }
}
